package com.lemon.rpcframe.dao.contract;

import java.util.Date;
import java.util.List;

import com.lemon.rpcframe.annotation.OperationContract;
import com.lemon.rpcframe.annotation.ServiceContract;
import com.lemon.rpcframe.dao.Total;
import com.lemon.rpcframe.dao.entity.TaskExecutableBean;

@ServiceContract
public interface ITaskExecutableService {

    /**
     * 
     * @param entity
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract long insert(TaskExecutableBean entity) throws Exception;

    /**
     * 
     * @param taskid
     * @param start
     * @param end
     * @param pageSize
     * @param page
     * @param total
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract List<TaskExecutableBean> loadByPage(long taskid, Date start, Date end, int pageSize, int page, Total<Integer> total) throws Exception;

    /**
     * 
     * @param taskid
     * @param start
     * @param end
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract int countByTaskId(long taskid, Date start, Date end) throws Exception;

    /**
     * 
     * @param taskGroup
     * @param running
     * @param nexttrigDate
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract TaskExecutableBean loadOneByGroupRunningTrigger(String taskGroup, boolean running, Date nexttrigDate) throws Exception;

    /**
     * 根据 jobID isrunning   更新一个任务的状态     isrunning会由false置为true
     * 可用来设置一个任务的完成状态
     * @param jobId
     * @param running
     * @param taskTrackerIdentity
     * @param modifyDate
     * @return  需要返回修改影响的行数  但SCF中默认的方法是void 如果有些业务依赖此返回值就会出问题
     *          先默认都返回1了
     * @throws Exception
     */
    @OperationContract
    public abstract int updateByJobIDRunning(long jobId, boolean running, String taskTrackerIdentity, Date modifyDate) throws Exception;

    /**
     * 根据JOBID根据一个任务的状态
     * 当发现一个任务为僵尸状态时 可以通过此接口将任务重置
     * @param jobId
     * @param taskTrackerIdentity
     * @param modifyDate
     * @param isrunning
     * @throws Exception
     */
    @OperationContract
    public abstract int updateByJobID(long jobId, String taskTrackerIdentity, Date modifyDate, boolean running) throws Exception;

    /**
     * 根据jobid和节点组  将其删除
     * @param jobid
     * @param taskTrackerNodeGroup
     * @throws Exception
     */
    @OperationContract
    public abstract void deleteByJobID(long jobid, String taskTrackerNodeGroup) throws Exception;

    /**
     * 根据状态 修改时间 查询待执行任务 
     * 可以查询僵尸任务
     * @param isRunning  运行状态
     * @param modifyDate 修改时间
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract List<TaskExecutableBean> loadByModifyRunning(boolean isRunning, Date modifyDate) throws Exception;

    /**
     * 查询待执行 的任务 按日期倒排
     * @param taskid
     * @param start
     * @param ends
     * @param pageSize
     * @param page
     * @param total
     * @return
     * @order nexttriggerdate desc 
     * @throws Exception
     */
    @OperationContract
    public abstract List<TaskExecutableBean> loadByPage(int pageSize, int page, Total<Integer> total) throws Exception;

    /**
     * 查询待执行的任务总量
     * @param taskid
     * @param start
     * @param end
     * @return
     * @throws Exception
     */
    @OperationContract
    public abstract int countAll() throws Exception;
}
